<?php
/**
 * Created By PhpStorm.
 * User: RenJianHong
 * Date: 2021-08-03 14:32
 */

namespace Modules\Order\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
use Modules\Order\Entities\OrderMessage;

class OrderMessage extends BaseModel
{
    protected $table = "order_message";
    protected $guarded = [];   

    public function getOrderType($type)
    {
        if($type == 0){
            return '商城订单';
        }else if($type == 1){
            return '秒杀订单';
        }else if($type == 2){
            return '拼团订单';
        }else if($type == 3){
            return '预约订单';
        }
    }

    /**
     * @param int $order_id 订单id
     * @param int $store_id
     * @param int $order_type 订单类型 0--商城订单 1--秒杀订单 2--拼团订单 3--预约订单 4--商户提交审核
     * @param int $type 类型  0--已下订单   1--售后订单
     * @return bool
     */
    public static function set($order_id, $order_type = 0, $type = 0)
    {
        if (empty($order_id)) {
            return false;
        }
        $model = OrderMessage::where([
            ['order_id' ,'=', $order_id],
            ['type' ,'=', $type],
            ['order_type' ,'=',$order_type]
        ])->first();
        if (!$model) {
            $model = new OrderMessage();
            $model->order_id = $order_id;
            $model->order_type = $order_type;
            $model->type = $type;
            $model->is_delete = 0;
            $model->is_read = 0;
            $model->is_sound = 0;
        }
        return $model->save();
    }
}